package controlebens.interceptor;

import br.com.caelum.vraptor.InterceptionException;
import br.com.caelum.vraptor.Intercepts;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.core.InterceptorStack;
import br.com.caelum.vraptor.interceptor.Interceptor;
import br.com.caelum.vraptor.resource.ResourceMethod;
import controlebens.controller.IndexController;
import controlebens.entidades.Login;

/**
 * @author Jefferson Stachelski
 */

@Intercepts
public class ControleInterceptor implements Interceptor {

    private Result result;
    private Login login;

    public ControleInterceptor(Result result, Login login) {
        this.result = result;
        this.login = login;
    }
    
    @Override
    public void intercept(InterceptorStack stack, ResourceMethod method, Object resourceInstance) throws InterceptionException {
        result.redirectTo(IndexController.class).index();
    }

    @Override
    public boolean accepts(ResourceMethod method) {
        //return false;
		return !login.isAutenticado() && !method.containsAnnotation(AcessoLiberado.class);
    }
    
}
